const cloud = require('wx-server-sdk')

cloud.init({
  env: "yt-active-8gnmft6y371c4f18"
})
const db = cloud.database();
const activeId = "4885635e676b67d10045012b049adf11";
async function log() {
  // 先取出集合记录总数
  const wxContext = cloud.getWXContext()
  const res = await db.collection('activelog').skip(0).limit(10).where({
    openId: wxContext.OPENID,
    forActive: activeId
  }).get()
  return {
    ...res.data[0]
  }
}
async function setAward(info) {
  const nums = info.nums
  console.log(info)
  await db.collection('award').doc(info._id).update({
    data: {
      nums: nums - 1
    }
  })
}
async function setLog(info, data) {
  await db.collection('activelog').doc(info._id).update({
    data
  })
}
module.exports = {
  log,
  setLog,
  setAward
}